package com.freesky.provider.content.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.freesky.common.enums.PanelPositionEnum;
import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.dao.entity.Panel;
import com.freesky.common.dao.entity.PanelContent;
import com.freesky.provider.content.service.ICommonService;
import com.freesky.provider.content.service.IOtherPanelContentService;
import com.freesky.provider.content.util.VOUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Freesky
 */
@Service
public class OtherPanelContentServiceImpl implements IOtherPanelContentService {

    @Autowired
    private ICommonService commonService;

    /**
     * 非首页其它板块positon为1或者2
     * @return
     */
    @Override
    public List<ZTreeNode> treeList() {
        Wrapper wrapper = new EntityWrapper().eq("position", PanelPositionEnum.ITEM_RECOMMEND).orderBy("sort_order", true);
        List<Panel> panelList  = new Panel().selectList(wrapper);
        //首页板块
        List<ZTreeNode> list = new ArrayList<>();
        for (Panel panel : panelList) {
            ZTreeNode zTreeNode = VOUtil.changePanelToZTreeNode(panel);
            list.add(zTreeNode);
        }

        return list;
    }

    @Override
    public DataTablesResult list(int panelId) {
        return commonService.getPanelContentListByPanelId(panelId);
    }

    @Override
    public JSONResponse delete(int[] ids) {
        return commonService.delete(ids);
    }

    @Override
    public JSONResponse update(PanelContent panelContent) {
        return commonService.updateContent(panelContent);
    }

}
